package org.lds.hotkey.console.business.rule.converter;

import org.lds.hotkey.console.business.rule.entity.Rule;
import org.lds.hotkey.console.business.rule.model.request.RuleBaseCreateRequest;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class RuleBaseCreateRequestToEntityConverter implements Converter<RuleBaseCreateRequest, Rule> {

    @Override
    public Rule convert(RuleBaseCreateRequest source) {
        LocalDateTime date = LocalDateTime.now();
        return Rule.builder()
                .appId(source.getAppId())
                .key(source.getKey())
                .prefix(source.getPrefix())
                .interval(source.getInterval())
                .threshold(source.getThreshold())
                .duration(source.getDuration())
                .desc(source.getDesc())
                .priority(source.getPriority())
                .creator(source.getCreator())
                .modifier(source.getModifier())
                .createTime(date)
                .updateTime(date)
                .build();
    }

}


